{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import syft as sy\n",
    "import torch as th\n",
    "import copy\n",
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "hook = sy.TorchHook(th)\n",
    "bob = sy.VirtualWorker(hook, id=\"bob\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, [1, [2, [[2, ['__add__', [11, [14906767764, 11608171820, 'bob', None, [2]]], [2, [[11, [14906767764, 11608171820, 'bob', None, [2]]]]]]], 20892737184]]]]\n",
      "[2, [1, [2, [[2, ['__mul__', [11, [14906767764, 11608171820, 'bob', None, [2]]], [2, [[11, [14906767764, 11608171820, 'bob', None, [2]]]]]]], 90538700932]]]]\n",
      "[2, [1, [2, [[2, ['__add__', [11, [65069091661, 20892737184, 'bob', None, None]], [2, [[11, [59942293716, 90538700932, 'bob', None, None]]]]]], 5995006905]]]]\n",
      "[2, [4, 20892737184]]\n",
      "[2, [4, 90538700932]]\n",
      "[2, [1, [2, [[2, ['abs', [11, [39980080112, 11608171820, 'bob', None, [2]]], [2, []]]], 31692265468]]]]\n",
      "[2, [1, [2, [[2, ['__neg__', [11, [37497737123, 31692265468, 'bob', None, None]], [2, []]]], 306590310]]]]\n",
      "[2, [4, 31692265468]]\n"
     ]
    }
   ],
   "source": [
    "@sy.func2plan(th.tensor([-1,-2]))\n",
    "def plan_a(data):\n",
    "    y = data + data\n",
    "    z = data * data\n",
    "    out = y + z\n",
    "    return out\n",
    "\n",
    "@sy.func2plan(th.tensor([-1,-2]))\n",
    "def plan_b(data):\n",
    "    return -data.abs()\n",
    "\n",
    "plan_a_ptr = plan_a.send(bob)\n",
    "plan_b_ptr = plan_b.send(bob)\n",
    "\n",
    "x = th.tensor([-1,2,3]).send(bob)\n",
    "\n",
    "plan_a_res = plan_a_ptr(x)\n",
    "plan_b_res = plan_b_ptr(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([1, 2, 3])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plan_a_res.get()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([-1, -2, -3])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plan_b_res.get()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{4304202390: <Plan id:4304202390 #tensors:0>,\n",
       " 8330432230: <Plan id:8330432230 #tensors:0>,\n",
       " 77985372853: tensor([-1,  2,  3])}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bob._objects"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
